--
-- Author:      feilong
-- DateTime:    2019-12-16 17:19:33
-- Description: 服务管理

require "skynet.manager"
local skynet = require "skynet"
local NodeMessage = import("NodeMessage")
local MessageDispatch = import("MessageDispatch")
local ClusterManager = import("ClusterManager")
local ServerInfo = import("ServerInfo")
local UserManager = import("UserManager")

local MessageHandler = import("manager.MessageHandler")
local ClientHandler = import("manager.ClientHandler")
local TableManager = import("manager.TableManager")

-- global = {} --服务只有一个全局变量，已在class.lua里声明

local function init()
	local node_message = NodeMessage.new()
	local message_dispatch = MessageDispatch.new()	
	local message_handler = MessageHandler.new(message_dispatch, node_message)
	local client_handler = ClientHandler.new(message_dispatch, node_message)	
	local cluster_manager = ClusterManager.new(message_dispatch)
	local server_info = ServerInfo.new() --节点相关信息
	local user_manager = UserManager.new()
	local table_manager = TableManager.new(message_dispatch, node_message)

	global.node_message = node_message
	global.message_dispatch = message_dispatch
	global.message_handler = message_handler
	global.cluster_manager = cluster_manager
	global.server_info = server_info
	global.client_handler = client_handler
	global.user_manager = user_manager
	global.table_manager = table_manager

	--lua消息的派发
	skynet.dispatch("lua", message_dispatch:dispatch())
	--开启集群节点
	global.cluster_manager:open(server_info)	
end

---------------------------------------------------------
-- skynet
---------------------------------------------------------

skynet.start(function()

	skynet.register('.manager')
	init()
end)


--